import type { 
  ITable,
  AsyncDataResult,
  AsyncVoid,
  PromiseBoolean,
  CreateTableParams,
  DropTableParams,
  TableExistsParams,
  TruncateTableParams,
  RenameTableParams,
  GetTableColumnsParams
} from '../../types'
import { HttpClient } from '../../HttpClient'

export class TableAPI implements ITable {
  private httpClient: HttpClient

  constructor(httpClient: HttpClient) {
    this.httpClient = httpClient
  }

  public async create(params: CreateTableParams): AsyncVoid {
    return await this.httpClient.request<CreateTableParams>('create_table', params)
  }

  public async drop(params: DropTableParams): AsyncVoid {
    return await this.httpClient.request<DropTableParams>('drop_table', params)
  }

  public async exists(params: TableExistsParams): PromiseBoolean {
    return await this.httpClient.request<TableExistsParams>('table_exists', params)
  }

  public async truncate(params: TruncateTableParams): AsyncVoid {
    return await this.httpClient.request<TruncateTableParams>('truncate_table', params)
  }

  public async rename(params: RenameTableParams): AsyncVoid {
    return await this.httpClient.request<RenameTableParams>('rename_table', params)
  }

  public async columns(params: GetTableColumnsParams): AsyncDataResult<string> {
    return await this.httpClient.request<GetTableColumnsParams>('get_table_columns', params)
  }
}
